<?php 
class Msms extends CI_Model{
	function __construct(){
		parent::__construct();
	}
	function loadSms(){
		$sql = "select s.*
				from tbsms s				
				order by id";
		$query = $this->db->query($sql);
		return $query->result();
	}
	function addSms($title,$content,$groupid,$remark,$username){
        if(!empty($username)){
            $uidArr = explode(',',$username);
            $valueArr = array();
            foreach($uidArr as $value){
                if(is_numeric($value)){
                    $valueArr[] = "('".$title."','".$content."','".$groupid."','".$remark."',$value,now())";
                }
            }
        }
        $valueStr = implode(',',$valueArr);
		$sql = "insert into tbsms(title,content,groupidstr,remark,username,createtime) values $valueStr";
		$query = $this->db->query($sql);
	}
	
	function getSmsById($id){		
		$sql = "select *
				from tbsms
				where id = ?";
		$query = $this->db->query($sql,array("$id"));
		$arr = array();
		foreach ($query->result() as $row){
			$arr['id'] = $id;
			$arr['title'] = $row->title;
			$arr["content"] = $row->content;
			$arr["remark"] = $row->remark;
			$arr["username"] = $row->username;
			$arr["groupidstr"] = $row->groupidstr;
			$arr["createtime"] = $row->createtime;			
		}
		return $arr;
	}
	function delSms($ids){
		$sql = "delete from tbsms where id in $ids";
		$this->db->query($sql);
	}
}
?>